<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<h1></h1>
	<script>
		//1.创建一个xhr对象
		var xhr = new XMLHttpRequest();
		//5.监听数据返回
		xhr.onreadystatechange = function() {
			if (xhr.readyState !== 4) {
				return;
			}
			if (xhr.staus >=200&&xhr.status <=300){
				var resp =JSON.parse(xhr.responseText);
				if(resp.result) {
					alert('登陆成功');
				}else {
					alert('登陆失败');
				}
			}else{
				console.log('请求失败');
			}
		}
		//2.配置这个对象
		xhr.open('post','./login.php',true);
		//3.设定请求头，指明body中的数据是何格式
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		//4.发送数据
		xhr.send('user=admin&&password=123456');
	</script>
</body>
</html>